import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import MyVant from '../views/MyVant.vue'
import NewsDetail from '../views/NewsDetail.vue'
// import UserView from '../views/UserView.vue'
import UserAdd from '../views/UserAdd.vue'
import LoginView from '../views/LoginView.vue'
import HealthView from '@/views/HealthView.vue';
import XingMing from '@/views/XingMing.vue';
import XingBie from '@/views/XingBie.vue';
import MyAdress from '@/views/MyAdress.vue';
import MyJob from '@/views/MyJob.vue';
import MyAdvice from '@/views/MyAdvice.vue';
import TelephoneNumber from '@/views/TelephoneNumber.vue';
Vue.use(VueRouter)

Vue.use(NewsDetail)

const routes = [{
        path: '/',
        name: 'home',
        component: HomeView
    }, 
    {
      path: '/zhiadd',
      name: 'zhiadd',
      component: () =>
    import ("../views/ZhiAdd.vue")

    },
    {
      path: '/hesuan',
      name: 'hesuan',
      component: () =>
    import ("../views/TongZhi.vue")

    },
    {
        path: '/vant',
        name: 'vant',
        component: MyVant
    },{
       path: '/vv',
        name: 'vv',
        component: () =>
      import ("../views/VideoView.vue")
    },
    {
      path:'/messg',
      name:'MessKn',
      component: () =>
      import ("../views/MessKn.vue")


    },
    {
      path: '/advice',
      name: 'advice',
      component: MyAdvice
  },

    {
        path: '/newsdetail/:id',
        name: 'newsdetail',
        component: NewsDetail
    }, {
        path: '/users',
        name: 'users',
        component: () =>
            import ("../views/UserView.vue")
    }, {
        path: '/login',
        name: 'Login',
        component: LoginView
    },
    {
        path: '/useradd',
        name: 'useradd',
        component: UserAdd
    }, {
        path: '/about',
        name: 'about',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () =>
            import ( /* webpackChunkName: "about" */ '../views/AboutView.vue')
    },
    {
        path: '/abc',
        name: 'AbC',
        component: () =>
            import ("../views/abc.vue")
    }, 
    {
      path: '/xiangqing',
      name: 'xiangqing',
      component: () =>
          import ("../views/XiangQing.vue")
  }, 
    {
        path: '/health',
        name: 'health',
        component: HealthView
      },
      {
        path: '/xingming',
        name: 'xingming',
        component: XingMing
      },
      {
        path: '/xingbie',
        name: 'xingbie',
        component: XingBie
      },
      {
        path: '/number',
        name: 'number',
        component: TelephoneNumber
      },
      {
        path: '/adress',
        name: 'adress',
        component: MyAdress
      },
      {
        path: '/job',
        name: 'job',
        component: MyJob
      },
      {
        path: '/zhiyuan',
        name: 'zhiyuan',
        component: () =>
          import ("../views/ZhiYuan.vue")
    },
    {
      path: '/haozhao',
      name: 'haozhao',
      component: () =>
        import ("../views/HaoZhao.vue")
  },
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

router.beforeEach((to, from, next) => {
    let isAuthenticated = localStorage.getItem('username')
    if (to.name !== 'Login' && !isAuthenticated) next({ name: 'Login' })
        // 如果用户未能验证身份，则 `next` 会被调用两次
    next()
})

export default router